<template>
	<view class="container">
		<view class="item-box" v-for="(item, index) in baoxiaoList" :key="index">
			<view class="item" @click="gotoBaoxiaoMessage(item.hr_expense_id)">
				<view class="item-header">
					<text class="item-title">{{ item.name }}</text>
					<text class="item-status" :class="{'pending': item.state === '待提交'}">{{ item.state }}</text>
				</view>
				
				<view class="item-content">
					<view class="info-row">
						<text class="info-label">公司：</text>
						<text class="info-value">{{ item.company }}</text>
					</view>
					<view class="info-row">
						<text class="info-label">日期：</text>
						<text class="info-value">{{ item.date }}</text>
					</view>
					<view class="info-row">
						<text class="info-label">申请人：</text>
						<text class="info-value">{{ item.employee }}</text>
					</view>
					<view class="info-row">
						<text class="info-label">支付方式：</text>
						<text class="info-value">{{ item.payment_mode }}</text>
					</view>
				</view>
				
				<view class="item-footer">
					<text class="amount-label">总金额：</text>
					<text class="amount-value">¥{{ item.total_amount || 0 }}</text>
				</view>
			</view>
		</view>
		
		<view v-if="baoxiaoList.length === 0" class="empty-tip">
			暂无报销单数据
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		ref
	} from 'vue'
	import {
		getBaoxiaoList
	} from '@/api/baoxiao.js'

	const recid = ref('')
	const baoxiaoList = ref([])

	const _getBaoxiaoList = () => {
		getBaoxiaoList(recid.value).then((res) => {
			console.log('报销单列表', res);
			if (res.hr_expense_list) {
				baoxiaoList.value = res.hr_expense_list
			}
		})
	}
	
	const gotoBaoxiaoMessage = (id) => {
		uni.navigateTo({
			url:`/model/baoXiao/baoxiaoMessage?id=${id}`
		})
	}


	onLoad((option) => {
		recid.value = option.id
		_getBaoxiaoList()
	})
</script>

<style lang="scss" scoped>
.container {
	padding: 20rpx;
	background-color: #f5f5f5;
	min-height: 100vh;
}

.item-box {
	margin-bottom: 20rpx;
	background-color: #fff;
	border-radius: 12rpx;
	overflow: hidden;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}

.item {
	padding: 24rpx;
}

.item-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 20rpx;
}

.item-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
}

.item-status {
	font-size: 26rpx;
	padding: 6rpx 12rpx;
	border-radius: 20rpx;
	
	&.pending {
		color: #ff9900;
		background-color: #fff8e6;
	}
}

.item-content {
	margin-bottom: 20rpx;
}

.info-row {
	display: flex;
	margin-bottom: 12rpx;
	font-size: 28rpx;
}

.info-label {
	color: #999;
	width: 140rpx;
}

.info-value {
	color: #666;
	flex: 1;
}

.item-footer {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	padding-top: 16rpx;
	border-top: 1rpx solid #eee;
}

.amount-label {
	font-size: 28rpx;
	color: #999;
	margin-right: 10rpx;
}

.amount-value {
	font-size: 36rpx;
	color: #ff5500;
	font-weight: bold;
}

.empty-tip {
	text-align: center;
	padding: 40rpx;
	color: #999;
	font-size: 28rpx;
}
</style>